package cn.imvc.app.controllers.system;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import cn.imvc.app.entities.Menu;
import cn.imvc.app.models.MenuModel;
import cn.imvc.app.models.RoleMenuModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;

public class RoleMenuControllerImpl implements RoleMenuController {

	public String roles;
	public int id;
	public String menus;
	public int[] menuid;
	public void setId(int id) {
		this.id = id;
	}
	@Autowired
	private RoleMenuModel roleMenuModel;
	@Autowired
	private MenuModel menuModel;
	public String index() {
		roles=roleMenuModel.getRoles();
		return "role-menu/index";
	}
	public String show() {
		menus=roleMenuModel.getMenuTree(id);
		return "role-menu/show";
	}
	public String create() {
		Set<Menu> menus=new HashSet<Menu>();
		if(menuid!=null)
		for (int mid : menuid) {
			menus.add(menuModel.get(mid));
		}
		roleMenuModel.saveRoleMenu(id,menus);
		
		return Render.json(new DialogBean("200", "保存成功","role-menu","closeCurrent"));
	}
	

}
